<template>
  <div class="category-wrapper">
    <div v-if="categoryOption.typeList.length" class="classify-item">
      <span class="name">类型：</span>
      <div class="classify-con">
        <span
          :class="{active: String(item.id) === searchForm[typeName||'type']}"
          v-for="(item) in categoryOption.typeList"
          :key="item.id"
          @click="handleSearch(item, typeName||'type')"
        >{{ item.name }}</span>
      </div>
    </div>
    <div v-if="currentItem.length" class="classify-item">
      <span class="name">类别：</span>
      <div class="classify-con">
        <span
          :class="{active: String(item.id) == searchForm.category}"
          v-for="(item,index) in currentItem"
          :key="index"
          @click="handleSearch(item, 'category')"
        >{{ item.name }}</span>
      </div>
    </div>
  </div>
</template>
<script>
import mapKeys from 'lodash/mapKeys'
export default {
  props: ['categoryOption', 'searchForm', 'typeName'],
  data () {
    return {}
  },
  computed: {
    categoryOptionMap () {
      const { typeList } = this.categoryOption
      return mapKeys(typeList, 'id')
    },
    type () {
      return this.searchForm.type
    },
    currentItem () {
      return this.categoryOptionMap[this.type].child || []
    }
  },
  methods: {
    handleSearch (i, p) {
      this.$emit('handleSearch', i, p)
    }
  }
}
</script>
<style lang="scss" scoped>
.category-wrapper {
  & > div {
    margin-bottom: 20px;
  }
  .name {
    display: inline-block;
    vertical-align: middle;
    height: 28px;
    line-height: 28px;
    color:  #666769;
  }
  .classify-item {
    &:last-child {
      margin-bottom: 0;
    }
  }
  .classify-con {
    display: inline-block;
    vertical-align: top;
    margin-left: 15px;
    max-width: 95%;
    & > span {
      display: inline-block;
      vertical-align: middle;
      padding: 0 20px;
      height: 28px;
      line-height: 28px;
      border-radius: 5px;
      color: #919397;
      cursor: pointer;
      i {
        font-size: 12px;
        color: #919397;
      }
      &:nth-of-type(1) {
        margin-left: 0;
      }
    }
    .active {
      border-color: #f74437;
      background-color: #f74437;
      color: #fff;
    }
    .tag {
      padding: 6px 10px;
      background-color: #fff;
      border: 1px solid #eff0f1;
      border-radius: 4px;
      i {
        margin-left: 5px;
        cursor: pointer;
        &:hover {
          opacity: 0.7;
        }
      }
    }
  }
}
</style>
